package 药品;

import com.alibaba.fastjson.JSONReader;

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class File {
    public static void main(String[] args) throws Exception{
//        JSONReader reader =new JSONReader(new FileReader("D:\\MP\\药品\\alldata.json"));
//        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\MP\\药品\\alldata.txt"));
//        reader.startArray();
//        while (reader.hasNext()){
//            data data = reader.readObject(data.class);
//            bw.write(data.toString());
//            bw.write("\n");
//            bw.flush();
//        }
//        reader.endArray();
//        bw.close();
        //因为是Json数组，因此使用JsonReader读取
        JSONReader reader = new JSONReader(new FileReader("D:\\MP\\药品\\alldata.json"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\MP\\药品\\alldata.txt"));
        //数组开始读取
        reader.startArray();
        while (reader.hasNext()) {
            //将Json数组的每一个元素转换成对象
            data data = reader.readObject(data.class);
            //写出对象
            bw.write(data.toString());
            bw.write("\n");
            //刷新，防止数据残留
            bw.flush();
        }
        //结束数组读取
        reader.endArray();
        bw.close();
    }
}
